/**
* 版权声明：厦门睿商网络科技有限公司 版权所有 违者必究
* 日    期：2020-04-27
*/
package com.rzico.account.controller;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.rzico.account.entity.CardBill;
import com.rzico.account.entity.Deposit;
import com.rzico.account.entity.Point;
import com.rzico.account.service.PointService;
import com.rzico.base.BaseController;
import com.rzico.base.CommResult;
import com.rzico.basics.entity.Enterprise;
import com.rzico.basics.entity.Member;
import com.rzico.basics.service.EnterpriseService;
import com.rzico.basics.service.MemberService;
import com.rzico.core.service.SysSequenceService;
import com.rzico.entity.PageResult;
import com.rzico.entity.Pageable;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.time.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 游戏金币账单控制层
 *
 * @author Rzico Boot
 * @version 1.0
 * @date 2020-04-27
 */
@Api(description = "游戏金币账单控制层")
@RestController
@RequestMapping("/game/point")
public class GamePointController extends BaseController {

    @Autowired
    private PointService pointService;

    @Autowired
    private MemberService memberService;


    /**
     * 获取当前可用金币余额
     *
     * @return
     */
    @ApiOperation("获取当前可用金币余额")
    @PostMapping("/getPoint")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "mchId", value = "商户号(珍农:10200)", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "mobile", value = "注册手机号", dataType = "String", paramType = "query")
    })
    public CommResult<Long> getPoint(String mchId,String mobile) {

        Member member = memberService.findByMchMobile(mchId,mobile);
        if (member==null) {
            return CommResult.error("会员没有注册");
        }
        return CommResult.success((Object) member.getPoint());

    }


    /**
     * 金币兑换成游戏币
     *
     * @param point
     * @return
     */
    @ApiOperation("金币兑换成游戏币")
    @PostMapping("/pointToGame")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "mchId", value = "商户号(珍农:10200)", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "mobile", value = "注册手机号", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "point", value = "兑换金币", dataType = "Integer", paramType = "query")
    })
    public CommResult<Long> pointToGame(String mchId,String mobile,Long point) {

        Member member = memberService.findByMchMobile(mchId,mobile);
        if (member==null) {
            return CommResult.error("会员没有注册");
        }

        if (member.getPoint().compareTo(point)<0) {
            return CommResult.error("金币余额不足");
        }

        pointService.decPoint(member.getId(),point,"兑换成游戏币",0,null);

        member = memberService.selectByPrimaryKey(member.getId());
        return CommResult.success((Object) member.getPoint());

    }


    /**
     * 游戏币兑换成金币
     *
     * @param point
     * @return
     */
    @ApiOperation("游戏币兑换成金币")
    @PostMapping("/gameToPoint")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "mchId", value = "商户号(珍农:10200)", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "mobile", value = "注册手机号", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "point", value = "兑换金币", dataType = "Integer", paramType = "query")
    })
    public CommResult<Long> gameToPoint(String mchId,String mobile,Long point) {
        Member member = memberService.findByMchMobile(mchId,mobile);
        if (member==null) {
            return CommResult.error("会员没有注册");
        }

        pointService.addPoint(member.getId(),point,"兑换成游戏币",0,null);

        member = memberService.selectByPrimaryKey(member.getId());
        return CommResult.success((Object) member.getPoint());
    }

}
